<?php
/** @var $this yii\web\View */
use frontend\models\Address;
use frontend\models\Order;
use yii\helpers\Url;
use yii\web\JqueryAsset;
use yii\widgets\ActiveForm;
$this->registerCssFile('/style/fillin.css');

$this->registerJsFile('/js/cart2.js',['depends'=>JqueryAsset::className()]);



?>
<!-- 页面头部 start -->
<div class="header w990 bc mt15">
    <div class="logo w990">
        <h2 class="fl"><a href="<?=Url::home();?>"><img src="/images/logo.png" alt="京西商城"></a></h2>
        <div class="flow fr flow2">
            <ul>
                <li>1.我的购物车</li>
                <li class="cur">2.填写核对订单信息</li>
                <li>3.成功提交订单</li>
            </ul>
        </div>
    </div>
</div>
<!-- 页面头部 end -->

<div style="clear:both;"></div>

<!-- 主体部分 start -->
<?php $form = ActiveForm::begin();?>

<div class="fillin w990 bc mt15">
    <div class="fillin_hd">
        <h2>填写并核对订单信息</h2>
    </div>

    <div class="fillin_bd">
        <!-- 收货人信息  start-->
        <div class="address">
            <h3>收货人信息</h3>
            <div class="address_info">
                    <?php
                    $addresses = Address::AddressArray();
                    if($addresses == null){
                        echo "<script>window.location.href='".Url::to(['address/list'])."'</script>";
                    }
                    foreach ($addresses as $key=>$address){
                        $addressInfo = implode('&nbsp;',$address);
                        echo "<p><input type='radio' value='{$address['id']}' checked='checked' name='Order[address_id]' />{$addressInfo}</p>";
                    };
                    ?>

            </div>

        <!-- 配送方式 start -->
        <div class="delivery">
            <h3>送货方式 </h3>
            <div class="delivery_select">
                <table>
                    <thead>
                    <tr>
                        <th class="col1">送货方式</th>
                        <th class="col2">运费</th>
                        <th class="col3">运费标准</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach(Order::$deliveries as $delivery):?>
                    <tr class="<?=$delivery['delivery_id']==1?'cur ':'';?>">
                        <td>
                            <input type="radio" name="Order[delivery]" value="<?=$delivery['delivery_id']?>" checked="checked" /><?=$delivery['delivery_name']?>
                          </td>
                        <td class="price">￥<span><?=$delivery['price']?></span></td>
                        <td><?=$delivery['evaluation']?></td>
                    </tr>
                    <?php endforeach;?>
            
                    </tbody>
                </table>
            </div>
        </div>
        <!-- 配送方式 end -->

        <!-- 支付方式  start-->
        <div class="pay">
            <h3>支付方式 </h3>
            

            <div class="pay_select ">
                <table>
				<?php foreach(Order::$payMethod as $key =>$method):?>
                    <tr class="<?=$key==1?'cur':'';?>">
                        <td class="col1"><input type="radio" name="Order[pay_id]" value="<?=$key?>"  checked="checked" /><?=$method['name']?></td>
                        <td class="col2"><?=$method['intro']?></td>
                    </tr>
                    <?php endforeach;?>
                </table>
            </div>
        </div>
        <!-- 支付方式  end-->

        

        <!-- 商品清单 start -->
        <div class="goods">
            <h3>商品清单</h3>
            <table>
                <thead>
                <tr>
                    <th class="col1">商品</th>
                    <th class="col3">价格</th>
                    <th class="col4">数量</th>
                    <th class="col5">小计</th>
                </tr>
                </thead>
                <tbody>
				<?php $count=0;$money=0?>
				<?php foreach($carts as $cart):?>
				<?php $count ++; $shop_price =$cart->amount*$cart->goods->shop_price;$money+=$shop_price; ?>
                <tr>
                    <td class="col1"><a href=""><img src="<?=$cart->goods->logoUrl()?>" alt="" /></a>  <strong><a href=""><?=$cart->goods->name?></a></strong></td>
                    <td class="col3">￥<?=$cart->goods->shop_price?></td>
                    <td class="col4"> <?=$cart->amount?></td>
                    <td class="col5"><span>￥<?=$shop_price?></span></td>
                </tr>
				<?php endforeach;?>
               
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="5">
                        <ul>
                            <li>
                                <span><?=$count?> 件商品，总商品金额：</span>
                                <em>￥<?=$money?></em>
                            </li>
                            
                            <li class="delivery_price">
                                <span>运费：￥</span>
                                <em>0.00</em>
                            </li>
                            <li class="total_price">
                                <span>应付总额：￥</span>
                                <em><?=$money?></em>
                            </li>
                        </ul>
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
        <!-- 商品清单 end -->

    </div>

    <div class="fillin_ft">
        <button><span>提交订单</span></button>
        <p>应付总额：￥<strong><?=$money?></strong>元</p>

    </div>
</div>
<?php ActiveForm::end();?>
<!-- 主体部分 end -->

    <?php
   $this->registerJs(<<<AOFO
   function changePrice(data){
       var price = $(this).closest("tr").find(".price span").text();
        var total = (parseInt(money)+parseInt(price));
        $(".fillin_ft strong").text(total);
        $(".total_price em").text(total);
        $(".delivery_price").find('em').text(price);
   }
   var money = {$money};
   
   $(".delivery_select").on('change','input[name="Order[delivery]"]',function(){ changePrice.apply(this);});
//
//function add(a,b)  
//{  
//    alert(a+b);  
//    alert(this);
//    
//}  
//function sub(a,b)  
//{  
//    alert(123);
//    alert(a-b);  
//}  
//  
//  add(3,1);
//add.call(sub,3,1);  
////add.apply(sub,[3,1]);
AOFO

    );




    ?>


<div style="clear:both;"></div>
<!-- 底部版权 start -->

